package com.adinnet.admin.sentence.controller;


import com.adinnet.admin.sentence.model.Sentence;
import com.adinnet.admin.sentence.service.SentenceService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 跟随训练表（短句） 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Controller
@RequestMapping("/sentence")
public class SentenceController {

    @Autowired
    private SentenceService sentenceService;

    /**
     * 短句列表
     **/
    @ResponseBody
    @RequestMapping("/list")
    public PageResult<Sentence> list(String keyword) {
        List<Sentence> sentenceList = sentenceService.sentenceList(keyword);
        return new PageResult<>(sentenceList);
    }

    /**
     * 添加短句
     */
    @RequestMapping("/add")
    @ResponseBody
    public JsonResult add(Sentence sentence) {
        if (sentenceService.save(sentence)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    /**
     * 修改短句
     */
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult update(Sentence sentence) {
        if (sentenceService.updateById(sentence)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    /**
     * 删除短句
     */
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Integer sentenceId) {
        return sentenceService.delete(sentenceId);
    }

}
